using System;
using System.Collections.Generic;
using System.Text;
using WindowsLive.Writer.Api;
using System.Windows.Forms;
using ScottIsAFool;

namespace InsertEmoticonPlugin
{
    [WriterPlugin("0feb58b4-cb36-4aee-9431-1a44af433946", "Emotify Post Plugin",
        Description = "Translates MSN emoticon codes into images on the blog post.",
        HasEditableOptions = true,
        Name = "Emotify plugin",        
        PublisherUrl = "http://scottisafooldev.spaces.live.com",
        ImagePath = "smile.gif"
        )]    

    public class Emotify : PublishNotificationHook
    {
        Settings m_default;
        ScottIsAFool scott;
        public override void Initialize(IProperties pluginOptions)
        {
            base.Initialize(pluginOptions);
            m_default = new Settings(pluginOptions);
            scott = new ScottIsAFool(m_default);            
        }

        public override bool OnPrePublish(IWin32Window dialogOwner, IProperties properties, IPublishingContext publishingContext, bool publish)
        {
            string source = publishingContext.PostInfo.Contents;
            if (m_default.Automatic)
            {
                //return SetPostContents(publishingContext.PostInfo, scott.Emotify(source));
                return WriterUtils.ReplaceText(publishingContext.PostInfo, scott.Emotify(source), PostItems.Contents);
            }
            else
            {
                DialogResult result = MessageBox.Show("Would you like to emotify your post?\n(Default can be set in Tools | Options | Plugins)", "Emotify?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    //return SetPostContents(publishingContext.PostInfo, scott.Emotify(source));
                    return WriterUtils.ReplaceText(publishingContext.PostInfo, scott.Emotify(source), PostItems.Contents);
                }
                else
                {
                    return true;
                }
            }
        }

        public override void EditOptions(IWin32Window dialogOwner)
        {
            frmOptions op = new frmOptions(m_default);
            op.ShowDialog();
        }

    }
}
